<template>
  <view class="register-container">
    <view class="register-box">
      <text class="register-title">注册</text>
      <view class="input-item">
        <input type="text" placeholder="请输入用户名" v-model="username" />
      </view>
      <view class="input-item">
        <input type="password" placeholder="请输入密码" v-model="password" />
      </view>
      <view class="input-item">
        <input type="password" placeholder="请确认密码" v-model="confirmPassword" />
      </view>
      <button class="register-button" @click="register">注册</button>
      <view class="login-link">
        <text>已有账号？</text>
        <text class="login-text" @click="goDetailPage('login')">去登录</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      password: '',
      confirmPassword: ''
    };
  },
  methods: {
    register() {
      if (!this.username) {
        uni.showToast({
          title: '请输入用户名',
          icon: 'none'
        });
        return;
      }
      if (!this.password) {
        uni.showToast({
          title: '请输入密码',
          icon: 'none'
        });
        return;
      }
      if (this.password !== this.confirmPassword) {
        uni.showToast({
          title: '两次输入的密码不一致',
          icon: 'none'
        });
        return;
      }
      console.log('用户名:', this.username);
      console.log('密码:', this.password);
      uni.showToast({
        title: '注册功能待实现，已打印输入信息',
        icon: 'none'
      });
    },
    goDetailPage(e) {
        if (typeof e === 'string') {
            uni.navigateTo({
    			url: '/pages/' + e + '/' + e
                });
        } else {
            uni.navigateTo({
                url: e.url
            });
        }
    }
  }
};
</script>

<style>
.register-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #fff;
}

.register-box {
  width: 80%;
  padding: 20px;
  background-color: #f5f5f5;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.register-title {
  display: block;
  text-align: center;
  font-size: 20px;
  margin-bottom: 20px;
}

.input-item {
  margin-bottom: 15px;
}

.input-item input {
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

.register-button {
  height: 40px;
  background-color: #007AFF;
  color: white;
  border: none;
  border-radius: 5px;
  margin-top: 10px;
}

.login-link {
  text-align: center;
  margin-top: 10px;
}

.login-text {
  color: #007AFF;
}
</style>